 /**
 * Description: 系统参数业务实现类
 * Copyright:Copyright 2018 nfky.com. All rights reserved
 * @author:xk
 * @since:0.0.1
 * Create at:2018-01-10 下午 19:40:19
 *  
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-01-10   xk       0.0.1     Initial
 */
package com.metro.paperless.sys.service.impl;

import com.metro.core.dao.IMapper;
import com.metro.core.service.BaseServiceSupport;
import com.metro.core.service.ServiceException;
import com.metro.core.vo.ResultCode;
import com.metro.core.vo.inf.IResult;
import com.metro.paperless.common.beans.constant.DicTypeEnum;
import com.metro.paperless.common.utils.DicUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.metro.paperless.sys.mapper.ISysPropertiesMapper;
import com.metro.paperless.sys.service.inf.ISysPropertiesService;
import com.metro.paperless.sys.beans.vo.SysProperties;

 /**
 * 系统参数业务实现类<br>
 *
 * @author xk
 * @since [0.0.1]
 * @version [0.0.1, 2018-01-10]
 */
@Service("sysPropertiesService")
public class SysPropertiesService extends BaseServiceSupport<SysProperties> implements ISysPropertiesService{
    //系统参数Mapper
    @Autowired
    private ISysPropertiesMapper sysPropertiesMapper;

    @Override
    public IMapper getMapper() {
        return sysPropertiesMapper;
    }

    @Override
    public IResult save(SysProperties entity) {
        try {
            sysPropertiesMapper.save(entity);
            DicUtil.removeKeyFromCache(DicTypeEnum.properties.name());
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("新增系统参数失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult update(SysProperties entity) {
        try {
            sysPropertiesMapper.update(entity);
            DicUtil.removeKeyFromCache(DicTypeEnum.properties.name());
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("修改系统参数失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult delete(Long id) {
        try {
            sysPropertiesMapper.delete(id);
            DicUtil.removeKeyFromCache(DicTypeEnum.properties.name());
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("删除失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult deleteByIds(String ids) {
        try {
            sysPropertiesMapper.deleteByIds(ids);
            DicUtil.removeKeyFromCache(DicTypeEnum.properties.name());
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("删除失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }
}